package com.bsoft.gol.hbs.service.impl;

import com.alibaba.fastjson.JSONObject;
import ctd.controller.exception.ControllerException;
import ctd.message.Message;
import ctd.spring.boot.annotation.SsdevService;
import ctd.util.annotation.RpcService;
import hcn.bean.ClearMessageBean;
import hcn.bean.PushMessageBean;
import hcn.service.base.qo.MsgTemplateQuery;
import hcn.util.BaseResponse;
import hcn.service.base.sendMsg.IMessageSyncService;
import hcn.service.base.sendMsg.MessageHandleService;
import hcn.util.ResultCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;
import org.springframework.beans.factory.annotation.Qualifier;

/**
 * @description:消息同步接口实现
 * @author: zhengcb10708
 * @create: 2020-09-28 14:18
 **/
@SsdevService("messageSyncService")
public class MessageSyncServiceImpl implements IMessageSyncService {
    private final static Logger log = LoggerFactory.getLogger(MessageSyncServiceImpl.class);
    @Autowired
    @Qualifier("messageHandleService")
    private MessageHandleService messageHandleService;

    /**
     * @Describe: 推送业务消息/生产消息-在业务流程和业务节点中有消息要推送给患者或者医生的通过这个接口进行推送，有些消息是待办事项消息的，需要调用下面的接口进行消息的清除，不清除会一直存在
     * @Param: [pushMessageBean]
     * @Return: BaseResponse
     * @Author: zhengcb10708
     * @Date: 2020/9/28 14:25
     */
    @RpcService
    @Override
    public BaseResponse productionMessage(PushMessageBean pushMessageBean) {
        log.info("执行发送消息productionMessage()"+ JSONObject.toJSONString(pushMessageBean));
        BaseResponse baseResponse = new BaseResponse();
        if (pushMessageBean != null) {
            baseResponse= messageHandleService.messageHandle(pushMessageBean);
        } else {
            baseResponse.setCode(ResultCode.PARAMETERS_MISSING);
            baseResponse.setMessage("传入的businessType不能为空");
            log.info("发送消息，传入的businessType为空{}", pushMessageBean);
        }
        return baseResponse;
    }
    @RpcService
    @Override
    public BaseResponse testNotifyByJPush(Message message) {
        return null;
    }

    /**
     * @param message
     * @Describe: 通过模板编码查询小程序id
     * @Param: [message]
     * @Return: BaseResponse
     * @Author: zhengcb10708
     * @Date: 2022/8/4 9:56
     */
    @Override
    public Map<String,Object> findMinAppletsIdByCd(MsgTemplateQuery message) throws ControllerException {
        //此处空实现。 具体在hcb-web 中
        return null;
    }

    /**
     * @Describe: 清除待办事项消息-在业务流程中患者或者医生已经完成或者取消待办事项要通过该接口清除已经推送的待办事项消息
     * @Param: [clearMessageBean]
     * @Return: BaseResponse
     * @Author: zhengcb10708
     * @Date: 2020/9/28 14:26
     */
    @Override
    public BaseResponse clearMessage(ClearMessageBean clearMessageBean) {
        return null;
    }
}
